<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page import = "com.sinodata.bsm.common.vo.*" %>
<%@ page import = "com.sinodata.bsm.center.util.spring.SpringContextHolder" %>
<%@ page import = "com.sinodata.bsm.center.service.config.PortalService" %>
<%@ include file="../include/taglib.jsp"%>
<%
	String pageId= request.getParameter("pageId");
	PortalService portalService = SpringContextHolder.getBean(PortalService.class);
	PagePortal portalPage = portalService.findUserPortalById(Long.parseLong(pageId));
%>
<html>
  <head>
    <title>编辑页面布局</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<%@ include file="../include/common.jsp"%>
  	<%@ include file="../include/tree.jsp"%>
  	<script type="text/javascript">
  	var pageId = '<%=pageId%>';
  	$(document).ready(function() {
  		$("#colLength").change(function() {
  			var left = new Number(this.value);
  			setColLength(left)
 		});
 		    var colLength = $('#colLength');
  	    var selectValue = colLength.val();
 		setColLength(selectValue);
  	});
  	function setColLength(val)
  	{
  		var colLength = '<%=portalPage.getColLength() %>';
  		var col1='<%=portalPage.getCol1() %>';
  		var col2='<%=portalPage.getCol2() %>';
  		var col3='<%=portalPage.getCol3() %>';
  		if(val==1){
  				$("#col1").attr("disabled", true).val(colLength==1?parseInt(col1):100);
  				$("#col2").attr("disabled", true).val(0);
  				$("#col3").attr("disabled", true).val(0);
  		}else if(val==2){
  				$("#col1").attr("disabled", false).val(colLength==2?parseInt(col1):55);
  				$("#col2").attr("disabled", false).val(colLength==2?parseInt(col2):45);
  				$("#col3").attr("disabled", true).val(0);
  		}else {
  				$("#col1").attr("disabled", false).val(colLength==3?parseInt(col1):30);
  				$("#col2").attr("disabled", false).val(colLength==3?parseInt(col2):40);
  				$("#col3").attr("disabled", false).val(colLength==3?parseInt(col3):30);
  			  }
  	}

  	function submitIt(){
  	    var colLength = $('#colLength');
  	    var selectValue = colLength.val();
  	    var col1Value = $("#col1").val();
  	    var col2Value = $("#col2").val();
  	    var col3Value = $("#col3").val();
  	    if(selectValue==2){
  	    	if(isNaN(col1Value)||isNaN(col2Value)){
  	    		getTopWin(window).getMessageBox().alert("列宽的值只能为数字","提示");
  	    		return ;
  	    	}
  	    	if((parseInt(col1Value)+parseInt(col2Value))>100){
  	    		getTopWin(window).getMessageBox().alert("列宽之和不能大于100","提示");
  	    		return;
  	    	}
  	    }else if(selectValue==3){
  	    	if(isNaN(col1Value)||isNaN(col2Value)||isNaN(col3Value)){
  	    		getTopWin(window).getMessageBox().alert("列宽的值只能为数字","提示");
  	    		return ;
  	    	}
  	    	if((parseInt(col1Value)+parseInt(col2Value)+parseInt(col3Value))>100){
  	    		getTopWin(window).getMessageBox().alert("列宽之和不能大于100","提示");
  	    		return;
  	    	}
  	    }
 		$.ajax({
			url : "../../portlet/portal!save.action",
			cache : false,
			global : false,
			async : false,
			data: $("#myform").serialize(), //传的参数
			success : function(items) {
				reloadPage();
				closewin();
			}
		});
  		
  	}
  	function reloadPage()
  	{
  		var win = getTopWin(window).currentWin["show-layout-module"];
  		win.reloadPage();
  	}
  function closewin(){
	   getTopWin(window).closejBox("show-layout-module");
  }
  	
  	</script>
  </head>
  <body style="height:80px; width:360px;">
  		<form action="" id="myform" name="myform" method="post" style="margin-left:8px; margin-top:8px;">
  			<input type="hidden" name="pageId" value="<%=portalPage.getId() %>">
    		<table class="table_eidt table_xeidt">
    			<tr>
	    			<td class="td_left" width="100px"><span class="span_alert">*</span>列数</td>
	    			<td  class="td_right" >
	    				<select name="colLength" id ="colLength"  style="width:227px; text-indent:3px;">
	    					<option value=1 <%if(portalPage.getColLength()==1)out.print("selected");%> >1</option>
	    					<option value=2 <%if(portalPage.getColLength()==2)out.print("selected");%> >2</option>
	    					<option value=3 <%if(portalPage.getColLength()==3)out.print("selected");%> >3</option>
	    				</select>
	    			</td>
    			</tr>
    			<tr>
	    			<td class="td_left"><span class="span_alert">*</span>列宽 1(%)</td>
	    			<td class="td_right"><input type="text" name="col1" id="col1" maxlength="2"  value="<%=portalPage.getCol1()==null ? "":portalPage.getCol1() %>" class="input_text"  onKeypress="if((event.keyCode<48 || event.keyCode>57 )) event.returnValue=false">
    			</tr>
    			<tr>
	    			<td class="td_left"><span class="span_alert">*</span>列宽 2(%)</td>
	    			<td class="td_right"><input type="text" name="col2" id="col2"  maxlength="2" value="<%=portalPage.getCol2()==null ? "":portalPage.getCol2() %>" class="input_text" onKeypress="if((event.keyCode<48 || event.keyCode>57 )) event.returnValue=false">
    			</tr>
    			<tr>
	    			<td class="td_left"><span class="span_alert">*</span>列宽 3(%)</td>
	    			<td class="td_right"><input type="text" name="col3" id="col3" maxlength="2"  value="<%=portalPage.getCol3()==null ? "":portalPage.getCol3() %>" class="input_text"  onKeypress="if((event.keyCode<48 || event.keyCode>57 )) event.returnValue=false">
    			</tr>
    		</table>
	<div  class="btn-div" style="margin-bottom:9px; margin-top:20px;" >
		<button type="button" id ="saveBt" value="保存" class="btn-4" onclick="submitIt();">提交</button>
    	<button type="button" onclick="closewin();" class="btn-4" >关闭</button>
    	</div>
    	</form>
  </body>
</html>
